-- ----------------------------------------------------------
--
-- Author: czf
-- date: 2018-12-14
-- description: 建造者模式-餐(记录购买食物)
--
-- ----------------------------------------------------------

Meal = Meal or BaseClass()

function Meal:__init()
	self.items = {}
end

-- 加入所需食物
function Meal:AddItem(item)
	table.insert(self.items, item)
end

-- 获得总价格
function Meal:GetCost()
	local cost = 0
	for _, item in ipairs(self.items or {}) do
		cost = cost + item:Price()
	end

	return cost
end

-- 按顺序打印购买物品
function Meal:ShowItems()
	for _, item in ipairs(self.items) do
		print("Item:" .. item:Name())
		print(", Packing : " .. item:Packing():Pack())
		print(", Price : " .. item:Price())
	end 
end